<!--
  * 时间：2024/10/25
  * 作者：刘岩
  * 描述：设备管理
-->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
<!--      <el-form-item label="设备名称" prop="name">-->
<!--        <el-input-->
<!--          v-model="queryParams.name"-->
<!--          placeholder="请输入设备名称"-->
<!--          clearable-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="展厅" prop="hallId">
        <el-select
          clearable
          placeholder="请选择展厅"
          v-model="queryParams.hallId"
          filterable
        >
          <el-option
            v-for="item in hallSearchOptions"
            :key="item.hallId"
            :value="item.hkRegionIndexCode"
            :label="item.hallName"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="equipmentList">
<!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="设备名称" align="center" prop="cn" />
      <el-table-column label="所属区域" align="center" prop="regionName" />
      <el-table-column label="设备状态" align="center" prop="online">
        <template slot-scope="scope">
          <span>{{ scope.row.online === 0 ? '离线' : scope.row.online === 1 ? '在线' : '' }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listEquipment } from "@/api/deviceManage";
import { listHall } from "@/api/exhibitionHallManage";

export default {
  name: "DeviceManage",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 设备表格数据
      equipmentList: [],
      // 查询参数
      queryParams: {
        name: null,
        pageNum: 1,
        pageSize: 10,
        shopId: null,
        hallId: null
      },
      // 展馆数据
      // shopSearchOptions: [],
      // 展厅数据
      hallSearchOptions: []
    };
  },
  created() {
    this.getList();
    this.getHallList();
  },
  methods: {
    /** 查询设备列表 */
    getList() {
      this.loading = true;
      listEquipment({
        // name: this.queryParams.name,
        pageNo: this.queryParams.pageNum,
        pageSize: this.queryParams.pageSize,
        includeSubNode: '1',
        regionId: this.queryParams.hallId
      }).then(res => {
        let data = JSON.parse(res.msg);
        this.equipmentList = data.data.list;
        this.total = data.data.total;
        this.loading = false;
      });
    },
    /**
     * 时间：2024/10/30
     * 作者：刘岩
     * 功能：查询展厅列表
     */
    getHallList() {
      listHall({
        pageNum: 1,
        pageSize: 99999,
        tenantId: this.$store.getters.tenantId
      }).then(response => {
       this.hallSearchOptions = response.rows;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    }
  }
}
</script>

<style scoped lang="scss">
.el-select--medium {
  width: 100%;
}
</style>
